geotiff: honour ModelTiepointTag when ModelPixelScaleTag is absent (#1750)#1760
Open
brendancol wants to merge 1 commit into
Open
geotiff: honour ModelTiepointTag when ModelPixelScaleTag is absent (#1750)#1760brendancol wants to merge 1 commit into
brendancol wants to merge 1 commit into
Conversation
…1750) `_extract_transform` previously returned the default `GeoTransform()` (origin (0, 0), unit pixel size) with `has_georef=True` whenever a ModelTiepointTag was present but ModelPixelScaleTag was missing. The tiepoint's tp_x / tp_y values were silently dropped, so any downstream code trusting `has_georef` constructed coordinates from origin (0, 0) and relocated the raster. Use the tiepoint's X / Y to build the origin (matching the tiepoint-with-scale branch) and fall back to the spec-documented unit pixel scale (1.0, -1.0). The alternative of returning has_georef=False would still mislabel the raster as having no georeferencing even though a real model X / Y is encoded in the tiepoint. Added `TestTiepointWithoutScale_1750` in test_geotags.py with a helper that emits a TIFF carrying ModelTiepointTag but no ModelPixelScaleTag. Verified the new tests fail on main (origin_x = 0.0 instead of the tiepoint X) and pass with the fix. Closes #1750.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes GeoTIFF georeferencing extraction for TIFFs that include ModelTiepointTag but omit ModelPixelScaleTag, ensuring the tiepoint’s model-space X/Y is honored instead of silently defaulting to an origin at (0, 0) while still claiming the raster is georeferenced.
Changes:
- Update
_extract_transform()to compute origin fromModelTiepointTageven whenModelPixelScaleTagis missing, using a unit-scale fallback. - Add regression tests that build a minimal TIFF containing only
ModelTiepointTagand validate the extracted origin and fallback pixel size behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
xrspatial/geotiff/_geotags.py |
Adjust tiepoint-only transform extraction to preserve the tiepoint-defined origin and apply a unit pixel-scale fallback. |
xrspatial/geotiff/tests/test_geotags.py |
Add regression tests and a minimal TIFF builder to validate tiepoint-only georeferencing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+263
to
+264
| real-world (X, Y) origin for pixel (I, J) and the pixel scale defaults | ||
| to (1.0, 1.0). |
Comment on lines
+466
to
+470
| # Tiepoint without scale: honour the tiepoint origin and fall back to | ||
| # unit pixel size. Per the GeoTIFF spec a ModelTiepointTag encodes a | ||
| # real-world (X, Y) for pixel (I, J); dropping it would silently relocate | ||
| # the raster to (0, 0). Unit scale (1.0, -1.0) is the documented fallback | ||
| # when ModelPixelScaleTag is absent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_extract_transform()returned a defaultGeoTransform()with origin (0, 0) andhas_georef=Truewhenever a TIFF carried ModelTiepointTag but no ModelPixelScaleTag, silently dropping the tiepoint's real-world X / Y. Downstream coordinate construction then placed the raster at (0, 0) with no warning.has_georef=Falseinstead. Rejected because the tiepoint encodes a real model X / Y; flagging the raster as ungeoreferenced would still mislabel it.Closes #1750.
Test plan
TestTiepointWithoutScale_1750inxrspatial/geotiff/tests/test_geotags.pybuilds a TIFF with ModelTiepointTag only, asserts the extracted origin equals tp_x / tp_y and that pixel scale falls back to (1.0, -1.0). Covers both tp_i=tp_j=0 and non-zero tp_i / tp_j cases.xrspatial/geotiff/tests/suite delta is identical to main; pre-existing GPU / matplotlib failures are unrelated to this change.